[
 {kernel, [
  %% Specifies the primary log level for Logger.
  %% Log events with the same, or a more severe level, pass through the primary log level check.
  %% This option is overwritten by MongooseIM config, once it is loaded.
  {logger_level, notice},

  {logger, [
    %% Default filters applied to all events before passing them to handlers:
    {filters, log, [
           %% If we want to see complete accumulator in logs
        %  {preserve_acc_filter, {fun mongoose_log_filter:preserve_acc_filter/2, no_state}},
           %% cowboy_req can leak some privacy data. So, we drop it from logs by default.
           {remove_fields_filter, {fun mongoose_log_filter:remove_fields_filter/2, [req, reply_body]}},
           {format_packet_filter, {fun mongoose_log_filter:format_packet_filter/2, no_state}},
           {format_acc_filter, {fun mongoose_log_filter:format_acc_filter/2, no_state}},
           {format_c2s_state_filter, {fun mongoose_log_filter:format_c2s_state_filter/2, no_state}},
           {format_stacktrace_filter, {fun mongoose_log_filter:format_stacktrace_filter/2, no_state}},
           {format_term_filter, {fun mongoose_log_filter:format_term_filter/2, [toml_value]}}
        ]},

    %% Shell log handler - it replaces the default one.
    %% Logger needs a handler named 'default', so if you want to silence shell logs,
    %% change the level to 'none' instead of removing this handler
    {handler, default, logger_std_h, #{
         level => all,
         formatter => {mongoose_flatlog_formatter, #{
           map_depth => 3,
           term_depth => 50
         }}
    }},

    %% There are two file handlers below, writing same log messages,
    %% but in different formats.
    %% Remove one of them, if you don't need it in production.
    %% Less handlers and less verbose log levels would improve performance.

    %% File log handler:
    {handler, disk_log, logger_disk_log_h, #{
         level => all,
         config => #{
           file => "{{mongooseim_log_dir}}/mongooseim.log",
           type => wrap,
           max_no_files => 5,
           max_no_bytes => 10485760, %% 10 Megabytes
           sync_mode_qlen => 2000, % If sync_mode_qlen is set to the same value as drop_mode_qlen,
           drop_mode_qlen => 2000, % synchronous mode is disabled. That is, the handler always runs
           flush_qlen => 5000,     % in asynchronous mode, unless dropping or flushing is invoked.
           overload_kill_enable => true
           % Documentation about Overload protection, together with default values, can be found here:
           % http://erlang.org/doc/apps/kernel/logger_chapter.html#protecting-the-handler-from-overload
         },
         formatter => {mongoose_flatlog_formatter, #{
           map_depth => 3,
           term_depth => 50
         }}
    }},

    %% JSON file log handler:
    {handler, disk_json_log, logger_disk_log_h, #{
         level => all,
         config => #{
           file => "{{mongooseim_log_dir}}/mongooseim.json",
           type => wrap,
           max_no_files => 5,
           max_no_bytes => 2097152,
           sync_mode_qlen => 2000, % If sync_mode_qlen is set to the same value as drop_mode_qlen,
           drop_mode_qlen => 2000, % synchronous mode is disabled. That is, the handler always runs
           flush_qlen => 5000,     % in asynchronous mode, unless dropping or flushing is invoked.
           overload_kill_enable => true
           % Documentation about Overload protection, together with default values, can be found here:
           % http://erlang.org/doc/apps/kernel/logger_chapter.html#protecting-the-handler-from-overload
         },
         formatter => {mongoose_json_formatter, #{
           format_depth => 10,
           format_chars_limit => 3000,
           depth => 10
         }}
    }}

  ]}]},

 % Uncomment these lines to enable logging to syslog.
 % Remember to add syslogger as a dependency in mongooseim.app.src.
%% {syslogger, [
%%     {ident, "mongooseim"},
%%     {logger, [
%%         {handler, sys_log, syslogger,
%%          #{formatter => {logger_formatter, #{single_line => true}}}}]}]
%% },

 {setup, [{verify_directories, false}]},
 {{mongooseim_mdb_dir_toggle}}{mnesia, [{dir, "{{mongooseim_mdb_dir}}"}]},
 {ssl, [
        {session_lifetime, 600}, % 10 minutes
        {protocol_version, ['tlsv1.2',
                            'tlsv1.3'
                           ]}
       ]},
 {nkservice, [
    %% Variable is called log_path, however it is used for caching
    {log_path, "{{nksip_cache_dir}}"}
 ]},
  %% Swagger spec
  {cowboy_swagger,
    [
      {global_spec,
        #{swagger => "2.0",
          info => #{
            title => "MongooseIM REST API",
            description =>
              "This is documentation of `MongooseIM REST API`.
              REST API for client developers [MongooseIM REST API](https://esl.github.io/MongooseDocs/latest/rest-api/Client-frontend/)",
            version => "0.1.0"
          }
        }
      }
    ]
  },
 {erlang_doctor, [{limit, {{erlang_doctor_limit}} }]}

%% use below line to enable FIPS mode
%%{crypto, [{fips_mode, true}]},
].

%% vim: filetype=erlang
